#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e5 + 10, M = N * 2;
int h[N], e[M], ne[M], idx;
int n, m;
int f[N];
int d[N];
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void tuopu()
{
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (!d[i]) {
			q.push(i);
			f[i] = 1;
		}
	}
	while (q.size()) {
		int t = q.front();
		q.pop();
		//cout << "t==" << t << endl;
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			f[j] = max(f[j], f[t] + 1);
			if (--d[j] == 0) {
				q.push(j);
			}
		}
	}
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		d[b]++;
		add(a, b);
	}
	tuopu();
	for (int i = 1; i <= n; i++) {
		cout << f[i] << endl;
	}
	return 0;
}